﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace 柴门牌文件批量更名工具
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button_浏览目录_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox_目录.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button_添加文件_Click(object sender, EventArgs e)
        {
            try
            {
                if (Directory.Exists(textBox_目录.Text) == false)
                {
                    MessageBox.Show("指定目录不存在，请指定一个目录", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //textBox_目录.Focus();
                    button_浏览目录_Click(null, null);
                    return;
                }
                if (String.IsNullOrEmpty(comboBox_文件类型.Text))
                {
                    MessageBox.Show("必须指定文件类型！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    comboBox_文件类型.Focus();
                    return;
                }
                System.Diagnostics.Debug.WriteLine("*." + comboBox_文件类型.Text);
                string[] fileList;
                try
                {
                    fileList = GetFileList(textBox_目录.Text, "*." + comboBox_文件类型.Text, checkBox_包含子目录.Checked);
                    foreach (string strFilePath in fileList)
                    {
                        listView_文件列表.Items.Add(new ListViewItem(new string[] { (listView_文件列表.Items.Count + 1).ToString(), Path.GetFileNameWithoutExtension(strFilePath), Path.GetExtension(strFilePath).Substring(1), Path.GetDirectoryName(strFilePath), "", "", "", "" }));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\n" + "*." + comboBox_文件类型.Text, "error1");
                }

                try
                {
                    if (checkBox_添加文件夹.Checked)
                    {
                        fileList = Directory.GetDirectories(textBox_目录.Text, "*.*", checkBox_包含子目录.Checked ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                        foreach (string strFilePath in fileList)
                        {
                            listView_文件列表.Items.Add(new ListViewItem(new string[] { (listView_文件列表.Items.Count + 1).ToString(), Path.GetFileName(strFilePath), "", Path.GetDirectoryName(strFilePath), "", "", "", "" }));
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "error2");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "error3");
            }
        }

        /// <summary>
        /// 获取文件夹下的文件列表
        /// </summary>
        /// <param name="Path">string Path：文件夹路径(@"C:\")</param>
        /// <param name="SearchPattern">string SearchPattern：扩展名过滤("*.txt")</param>
        /// <param name="SearchChild">bool SearchChild：为False不搜索子目录，为True搜索子目录</param>
        /// <returns></returns>
        public string[] GetFileList(string Path, string SearchPattern, bool SearchChild)
        {
            //判断文件夹是否存在
            if (Directory.Exists(Path) == false)
            {
                return null;
            }
            if (SearchChild)
            {
                //搜索子目录
                return Directory.GetFiles(Path, SearchPattern, SearchOption.AllDirectories);
            }
            else
            {
                //不搜索子目录
                return Directory.GetFiles(Path, SearchPattern, SearchOption.TopDirectoryOnly);
            }
        }

        private void button_清空文件_Click(object sender, EventArgs e)
        {
            listView_文件列表.Items.Clear();
        }

        private void radioButton_添加前缀_CheckedChanged(object sender, EventArgs e)
        {
            radioButton_更名_CheckedChanged(null, null);
        }

        private void radioButton_添加后缀_CheckedChanged(object sender, EventArgs e)
        {
            radioButton_更名_CheckedChanged(null, null);
        }

        private void radioButton_删除前缀_CheckedChanged(object sender, EventArgs e)
        {
            textBox_删除的位数.Enabled = (radioButton_删除前缀.Checked || radioButton__删除后缀.Checked) ? true : false;
        }

        private void radioButton__删除后缀_CheckedChanged(object sender, EventArgs e)
        {
            textBox_删除的位数.Enabled = (radioButton_删除前缀.Checked || radioButton__删除后缀.Checked) ? true : false;
        }

        private void radioButton_更名_CheckedChanged(object sender, EventArgs e)
        {
            textBox_更名前缀整数位.Enabled = (radioButton_更名.Checked || radioButton_添加后缀.Checked || radioButton_添加前缀.Checked);
            textBox_更名后缀整数位.Enabled = textBox_更名前缀整数位.Enabled;
            textBox_更名字符.Enabled = textBox_更名前缀整数位.Enabled;
        }

        private void radioButton_替换字符_CheckedChanged(object sender, EventArgs e)
        {
            textBox_替换原字符.Enabled = radioButton_替换字符.Checked;
            textBox_替换新字符.Enabled = radioButton_替换字符.Checked;
        }

        private void radioButton_正则_CheckedChanged(object sender, EventArgs e)
        {
            textBox_正则原字符.Enabled = radioButton_正则.Checked;
            textBox_正则新字符.Enabled = radioButton_正则.Checked;
            comboBox_常用正则.Enabled = radioButton_正则.Checked;
            checkBox_正则不区分大小写.Enabled = radioButton_正则.Checked;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            toolTip_提示.SetToolTip(textBox_删除的位数, "当填入的数字≥原名字符数时不做任何更改");
            toolTip_提示.SetToolTip(textBox_替换新字符, "这里留空即是删除原字符");
            toolTip_提示.SetToolTip(checkBox_正则不区分大小写, "默认不区分大小写【windows系统对文件名是不区分大小写的】");
            toolTip_提示.SetToolTip(listView_文件列表, "选中某些项之后按下Delete键可删除相应的项");

            try
            {
                STA.Settings.INIFile inifile = new STA.Settings.INIFile(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "常用正则.ini"));
                for (int i = 0; i < inifile.Sections.Count; i++)
                {
                    comboBox_常用正则.Items.Add(inifile.GetValue(i.ToString(), "名称", ""));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button_更名预览_Click(object sender, EventArgs e)
        {
            if (radioButton_添加前缀.Checked || radioButton_添加后缀.Checked)
            {
                int i前缀位数 = 0;
                int.TryParse(textBox_更名前缀整数位.Text, out i前缀位数);
                int i后缀位数 = 0;
                int.TryParse(textBox_更名后缀整数位.Text, out i后缀位数);
                if ((i前缀位数 <= 0) && (i后缀位数 <= 0) && string.IsNullOrEmpty(textBox_更名字符.Text))
                {
                    MessageBox.Show("填写错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    textBox_更名前缀整数位.Focus();
                    return;
                }
                string str前后缀;
                foreach (ListViewItem item in listView_文件列表.Items)
                {
                    str前后缀 = (i前缀位数==0) ? "" : item.SubItems[0].Text.PadLeft(i前缀位数, '0');
                    str前后缀 = str前后缀 + textBox_更名字符.Text;
                    str前后缀 = (i后缀位数==0) ? str前后缀 : ( str前后缀 + item.SubItems[0].Text.PadLeft(i后缀位数, '0') );
                    if (radioButton_处理文件名.Checked)
                    {
                        item.SubItems[4].Text = radioButton_添加前缀.Checked ? (str前后缀 + item.SubItems[1].Text) : (item.SubItems[1].Text + str前后缀);
                        item.SubItems[5].Text = "";
                    }
                    else
                    {//处理后缀名
                        item.SubItems[5].Text = radioButton_添加前缀.Checked ? (str前后缀 + item.SubItems[2].Text) : (item.SubItems[2].Text + str前后缀);
                        item.SubItems[4].Text = "";
                    }
                }
            }
            else if (radioButton_更名.Checked)
            {
                int i前缀位数 = 0;
                int.TryParse(textBox_更名前缀整数位.Text, out i前缀位数);
                int i后缀位数 = 0;
                int.TryParse(textBox_更名后缀整数位.Text, out i后缀位数);
                if ((i前缀位数 <= 0) && (i后缀位数 <= 0) && string.IsNullOrEmpty(textBox_更名字符.Text))
                {
                    MessageBox.Show("填写错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    textBox_更名前缀整数位.Focus();
                    return;
                }
                string str新名;
                foreach (ListViewItem item in listView_文件列表.Items)
                {
                    str新名 = (i前缀位数 == 0) ? "" : item.SubItems[0].Text.PadLeft(i前缀位数, '0');
                    str新名 = str新名 + textBox_更名字符.Text;
                    str新名 = (i后缀位数 == 0) ? str新名 : (str新名 + item.SubItems[0].Text.PadLeft(i后缀位数, '0'));
                    if (radioButton_处理文件名.Checked)
                    {
                        item.SubItems[4].Text = str新名;
                        item.SubItems[5].Text = "";
                    }
                    else
                    {//处理后缀名
                        item.SubItems[5].Text = str新名;
                        item.SubItems[4].Text = "";
                    }
                }
            }
            else if (radioButton_删除前缀.Checked)
            {
                int i位数 = 0;
                int.TryParse(textBox_删除的位数.Text, out i位数);
                foreach (ListViewItem item in listView_文件列表.Items)
                {
                    if (radioButton_处理文件名.Checked)
                    {
                        if(item.SubItems[1].Text.Length > i位数)
                        {
                            item.SubItems[4].Text = item.SubItems[1].Text.Substring(i位数);
                        }
                        else
                        {
                            item.SubItems[4].Text = item.SubItems[1].Text;
                        }
                        item.SubItems[5].Text = "";
                    }
                    else
                    {//处理后缀名
                        if(item.SubItems[2].Text.Length > i位数)
                        {
                            item.SubItems[5].Text = item.SubItems[2].Text.Substring(i位数);
                        }
                        else
                        {
                            item.SubItems[5].Text = item.SubItems[2].Text;
                        }
                        item.SubItems[4].Text = "";
                    }
                }
            }
            else if (radioButton__删除后缀.Checked)
            {
                int i位数 = 0;
                int.TryParse(textBox_删除的位数.Text, out i位数);
                foreach (ListViewItem item in listView_文件列表.Items)
                {
                    if (radioButton_处理文件名.Checked)
                    {
                        if(item.SubItems[1].Text.Length > i位数)
                        {
                            item.SubItems[4].Text = item.SubItems[1].Text.Substring(0, item.SubItems[1].Text.Length - i位数);
                        }
                        else
                        {
                            item.SubItems[4].Text = item.SubItems[1].Text;
                        }
                        item.SubItems[5].Text = "";
                    }
                    else
                    {//处理后缀名
                        if(item.SubItems[2].Text.Length > i位数)
                        {
                            item.SubItems[5].Text = item.SubItems[2].Text.Substring(0, item.SubItems[2].Text.Length - i位数);
                        }
                        else
                        {
                            item.SubItems[5].Text = item.SubItems[2].Text;
                        }
                        item.SubItems[4].Text = "";
                    }
                }
            }
            else if (radioButton_替换字符.Checked)
            {
                if (string.IsNullOrEmpty(textBox_替换原字符.Text))
                {
                    MessageBox.Show("必须填写原字符", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    textBox_替换原字符.Focus();
                    return;
                }
                foreach (ListViewItem item in listView_文件列表.Items)
                {
                    if (radioButton_处理文件名.Checked)
                    {
                        item.SubItems[4].Text = item.SubItems[1].Text.Replace(textBox_替换原字符.Text, textBox_替换新字符.Text);
                        item.SubItems[5].Text = "";
                    }
                    else
                    {//处理后缀名
                        item.SubItems[5].Text = item.SubItems[2].Text.Replace(textBox_替换原字符.Text, textBox_替换新字符.Text);
                        item.SubItems[4].Text = "";
                    }
                }
            }
            else if (radioButton_正则.Checked)
            {
                if (string.IsNullOrEmpty(textBox_正则原字符.Text))
                {
                    MessageBox.Show("必须填写原字符", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    textBox_正则原字符.Focus();
                    return;
                }
                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(textBox_正则原字符.Text, checkBox_正则不区分大小写.Checked ? System.Text.RegularExpressions.RegexOptions.IgnoreCase : System.Text.RegularExpressions.RegexOptions.None);
                foreach (ListViewItem item in listView_文件列表.Items)
                {
                    if (radioButton_处理文件名.Checked)
                    {
                        item.SubItems[4].Text = regex.Replace(item.SubItems[1].Text, textBox_正则新字符.Text);
                        item.SubItems[5].Text = "";
                    }
                    else
                    {//处理后缀名
                        item.SubItems[5].Text = regex.Replace(item.SubItems[2].Text, textBox_正则新字符.Text);
                        item.SubItems[4].Text = "";
                    }
                }
            }
        }

        private void comboBox_常用正则_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                STA.Settings.INIFile inifile = new STA.Settings.INIFile(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "常用正则.ini"));
                textBox_正则原字符.AppendText(inifile.GetValue(comboBox_常用正则.SelectedIndex.ToString(), "查找", ""));
                textBox_正则新字符.AppendText(inifile.GetValue(comboBox_常用正则.SelectedIndex.ToString(), "替换", ""));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            /*switch (comboBox_常用正则.SelectedIndex)
            {
                case 0:
                    //删除文件名起始处的所有数字
                    textBox_正则原字符.Text = @"^\d+";
                    textBox_正则新字符.Text = "";
                    break;
                case 1:
                    //删除文件名结尾处的所有数字
                    textBox_正则原字符.Text = @"\d+$";
                    textBox_正则新字符.Text = "";
                    break;
                case 2:
                    //在文件名的数字前添加添加一个“-”
                    textBox_正则原字符.Text = @"(\d+)";
                    textBox_正则新字符.Text = "-$1";
                    break;
                case 3:
                    //在文件名的数字后添加添加一个“-”
                    textBox_正则原字符.Text = @"(\d+)";
                    textBox_正则新字符.Text = "$1-";
                    break;
                case 4:
                    //匹配中文字符
                    textBox_正则原字符.AppendText(@"[\u4e00-\u9fa5]");
                    break;
                case 5:
                    //匹配整数
                    textBox_正则原字符.AppendText(@"\d+");
                    break;
                case 6:
                    //匹配小数
                    textBox_正则原字符.AppendText(@"\d+\.\d+");
                    break;
                case 7:
                    //匹配2个连续的相同的字符
                    textBox_正则原字符.AppendText(@"(.)\1");
                    break;
                default:
                    break;
            }*/
        }

        private void 转义符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\");
        }

        private void 或ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("|");
        }

        private void 匹配单个任意的字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText(".");
        }

        private void 标记一个子表达式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("()");
        }

        private void 非获取匹配ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("(?:)");
        }

        private void 正向预查ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("(?=)");
        }

        private void 负向预查ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("(?!)");
        }

        private void nm匹配ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("[nm]");
        }

        private void nm匹配任意未包含的字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("[^nm]");
        }

        private void nm匹配ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("[n-m]");
        }

        private void nm匹配不在指定范围内的任意字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("[^n-m]");
        }

        private void 匹配输入字符串的开始位置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("^");
        }

        private void 匹配输入字符串的结束位置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("$");
        }

        private void b匹配一个单词的边界ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\b");
        }

        private void b匹配非单词边界ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\B");
        }

        private void 零次或一次ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("?");
        }

        private void 零次或多次ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("*");
        }

        private void 一次或多次ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("+");
        }

        private void n匹配n次ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("{n}");
        }

        private void n至少匹配n次ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("{n,}");
        }

        private void nm至少匹配n次且最多匹配m次ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("{n,m}");
        }

        private void d匹配一个数字字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\d");
        }

        private void d匹配一个非数字字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\D");
        }

        private void f匹配一个换页符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\f");
        }

        private void r匹配一个回车符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\r");
        }

        private void n匹配一个换行符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\n");
        }

        private void s匹配任何空白字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\s");
        }

        private void s匹配任何非空白字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\S");
        }

        private void t匹配一个制表符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\t");
        }

        private void v匹配一个垂直制表符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\v");
        }

        private void w匹配一个包括下划线在内的单词字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\w");
        }

        private void w匹配任何非单词字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\W");
        }

        private void num引用获取的子表达式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\num");
        }

        private void cx匹配控制字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\cx");
        }

        private void xn匹配一个字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\xn");
        }

        private void un匹配一个unicode字符ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox_正则原字符.AppendText("\\un");
        }

        private void button_更名_Click(object sender, EventArgs e)
        {
            try
            {
                button_更名预览_Click(null, null);
                if (MessageBox.Show("确定要执行更名操作？", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
                string fileFullName = "";
                foreach (ListViewItem item in listView_文件列表.Items)
                {
                    if (string.IsNullOrEmpty(item.SubItems[2].Text))
                    {
                        item.SubItems[7].Text = item.SubItems[1].Text;
                    }
                    else
                    {
                        item.SubItems[7].Text = item.SubItems[1].Text + "." + item.SubItems[2].Text;
                    }
                    if (radioButton_处理文件名.Checked)
                    {
                        fileFullName = item.SubItems[4].Text + (string.IsNullOrEmpty(item.SubItems[2].Text) ? "" : ("." + item.SubItems[2].Text));
                        try
                        {
                        	if (File.GetAttributes(Path.Combine(item.SubItems[3].Text, item.SubItems[7].Text)) == FileAttributes.Directory) {
                        		System.IO.Directory.Move(System.IO.Path.Combine(item.SubItems[3].Text, item.SubItems[7].Text), System.IO.Path.Combine(item.SubItems[3].Text, fileFullName));
                        	}
                        	else {
                        		System.IO.File.Move(System.IO.Path.Combine(item.SubItems[3].Text, item.SubItems[7].Text), System.IO.Path.Combine(item.SubItems[3].Text, fileFullName));
                        	}
                            item.SubItems[1].Text = item.SubItems[4].Text;
                            item.SubItems[6].Text = "成功";
                        }
                        catch (Exception ex)
                        {
                            item.SubItems[6].Text = ex.Message;
                        }
                    }
                    else
                    {//处理后缀名
                        fileFullName = item.SubItems[1].Text + (string.IsNullOrEmpty(item.SubItems[5].Text) ? "" : ("." + item.SubItems[5].Text));
                        try
                        {
                            System.IO.File.Move(System.IO.Path.Combine(item.SubItems[3].Text, item.SubItems[7].Text), System.IO.Path.Combine(item.SubItems[3].Text, fileFullName));
                            item.SubItems[2].Text = item.SubItems[5].Text;
                            item.SubItems[6].Text = "成功";
                        }
                        catch (Exception ex)
                        {
                            item.SubItems[6].Text = ex.Message;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button_撤销更名_Click(object sender, EventArgs e)
        {
            try
            {
                //System.Diagnostics.Debug.WriteLine(System.IO.Path.GetFileNameWithoutExtension("asdfl.123"));
                //System.Diagnostics.Debug.WriteLine(System.IO.Path.GetExtension("asdfl.123"));
                string fileFullName = "";
                foreach (ListViewItem item in listView_文件列表.Items)
                {
                    if (string.IsNullOrEmpty(item.SubItems[7].Text))
                    {
                        continue;
                    }
                    fileFullName = item.SubItems[1].Text + (string.IsNullOrEmpty(item.SubItems[2].Text) ? "" : ("." + item.SubItems[2].Text));
                    try
                    {
                        System.IO.File.Move(System.IO.Path.Combine(item.SubItems[3].Text, fileFullName), System.IO.Path.Combine(item.SubItems[3].Text, item.SubItems[7].Text));
                        item.SubItems[1].Text = Path.GetFileNameWithoutExtension(item.SubItems[7].Text);
                        item.SubItems[2].Text = Path.GetExtension(item.SubItems[7].Text).Substring(1);
                        item.SubItems[6].Text = "成功";
                    }
                    catch (Exception ex)
                    {
                        item.SubItems[6].Text = ex.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void listView_文件列表_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                foreach (ListViewItem item in listView_文件列表.SelectedItems)
                {
                    listView_文件列表.Items.Remove(item);
                }
            }
        }
    }
}
